package com.gongpingjialoan.view;

import android.app.AlertDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.gongpingjialoan.R;
import com.gongpingjialoan.activity.vip.VIPDetailActivity;

/**
 * Created by Administrator on 2017/4/6.
 */
public class VIPBuyDialog extends AlertDialog {
    Context mContext;

    int pic;
    String des;

    int start;
    int end;


    public VIPBuyDialog(Context context) {
        super(context, R.style.dialogs);
        mContext = context;
    }


    public VIPBuyDialog(Context context, int pic, String des) {
        super(context, R.style.dialogs);
        mContext = context;
        this.pic = pic;
        this.des = des;

    }


    public VIPBuyDialog(Context context, int pic, String des, int start, int end) {
        super(context, R.style.dialogs);
        mContext = context;
        this.pic = pic;
        this.des = des;
        this.start = start;
        this.end = end;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vip_buy_dialog);

        findViewById(R.id.buy).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent it = new Intent(mContext, VIPDetailActivity.class);
                mContext.startActivity(it);
                dismiss();
            }
        });


        findViewById(R.id.bg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });

        ImageView picI = (ImageView) findViewById(R.id.pic);
        TextView desT = (TextView) findViewById(R.id.des);
        if (pic != 0) {
            picI.setImageResource(pic);
        }

        if (!TextUtils.isEmpty(des)) {
            if (start != 0) {
                SpannableStringBuilder builder = new SpannableStringBuilder(des);
                ForegroundColorSpan redSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.text_red));
                builder.setSpan(redSpan, start, end, 0x21);
                desT.setText(builder);
                findViewById(R.id.buy).setVisibility(View.GONE);
            } else {
                desT.setText(des);
                findViewById(R.id.buy).setVisibility(View.VISIBLE);
            }

        }


//        findViewById(R.id.close).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dismiss();
//            }
//        });
    }
}
